#import "BWBackStitch.h"
#import "BWThread.h"

@implementation  BWBackStitch

- (id) initWithStartRow: (int) sr
            startColumn: (int) sc
               quadrant: (BWGrid_Quadrant) sq
                 endRow: (int) er
              endColumn: (int) ec
               quadrant: (BWGrid_Quadrant) eq
                 thread: (BWThread *) t
{
    if (self = [super init]) {
        startRow = sr;
        startColumn = sc;
        startQuadrant = sq;
        endRow = er;
        endColumn = ec;
        endQuadrant = eq;

        thread = [t retain];
    }

    return (self);

} // initWithStartRow


- (void) dealloc
{
    [thread release];

    [super dealloc];

} // dealloc


- (int) startRow
{
    return (startRow);
} // startRow


- (int) startColumn
{
    return (startColumn);
} // startColumn


- (int) endRow
{
    return (endRow);
} // endRow


- (int) endColumn
{
    return (endColumn);
} // endColumn


- (BWGrid_Quadrant) startQuadrant
{
    return (startQuadrant);
} // quadrant


- (BWGrid_Quadrant) endQuadrant
{
    return (endQuadrant);
} // endQuadrant


- (BWThread *) thread
{
    return (thread);
} // thread


- (void) setStartRow: (int) row
              column: (int) column
            quadrant: (BWGrid_Quadrant) quadrant
{
    startRow = row;
    startColumn = column;
    startQuadrant = quadrant;

} // setStartRow


- (void) setEndRow: (int) row
            column: (int) column
          quadrant: (BWGrid_Quadrant) quadrant
{
    endRow = row;
    endColumn = column;
    endQuadrant = quadrant;

} // setEndRow


- (void) setThread: (BWThread *) t
{
    [t retain];
    [thread release];

    thread = t;

} // setThread


- (void) encodeWithCoder: (NSCoder *) coder
{
    [coder encodeValueOfObjCType: @encode(int)
           at: &startRow];
    [coder encodeValueOfObjCType: @encode(int)
           at: &startColumn];
    [coder encodeValueOfObjCType: @encode(BWBackStitch_Part)
           at: &startQuadrant];

    [coder encodeValueOfObjCType: @encode(int)
           at: &endRow];
    [coder encodeValueOfObjCType: @encode(int)
           at: &endColumn];
    [coder encodeValueOfObjCType: @encode(BWBackStitch_Part)
           at: &endQuadrant];

    [coder encodeObject: thread];

} // encodeWithCoder


- (id) initWithCoder: (NSCoder *) coder
{
    if (self = [super init]) {

        [coder decodeValueOfObjCType: @encode(int)
               at: &startRow];
        [coder decodeValueOfObjCType: @encode(int)
               at: &startColumn];
        [coder decodeValueOfObjCType: @encode(BWBackStitch_Part)
               at: &startQuadrant];

        [coder decodeValueOfObjCType: @encode(int)
               at: &endRow];
        [coder decodeValueOfObjCType: @encode(int)
               at: &endColumn];
        [coder decodeValueOfObjCType: @encode(BWBackStitch_Part)
               at: &endQuadrant];

        thread = [[coder decodeObject] retain];
    }
    
    return (self);

} // initWithCoder

@end // BWBackStitch

